package team.first.moiveapiv1.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import team.first.moiveapiv1.domain.Staff;
import team.first.moiveapiv1.dto.RequestStaff;
import team.first.moiveapiv1.mapper.StaffMapper;
import team.first.moiveapiv1.service.StaffService;
import team.first.moiveapiv1.vo.ResponseInnerMovie;
import team.first.moiveapiv1.vo.ResponseInnerStaff;

import java.util.List;

/**
 * @Author: HAPPY
 * @Project_name: project
 * @Package_name: team.first.moiveapiv1.service.impl
 * @Date: 2021/11/25 11:00
 * @Description：
 */
@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements StaffService {

    @Autowired
    StaffMapper staffMapper;

    @Override
    public List<ResponseInnerStaff> getAllStaffsByMovieId(Integer movieId) {
        return staffMapper.selectAllStaffsByMovieId(movieId);
    }

    @Override
    public List<ResponseInnerMovie> getAllMoviesByStaffId(Integer staffId, Integer roleTypeId) {
        return staffMapper.selectAllMoviesByStaffId(staffId, roleTypeId);
    }

    @Override
    public List<Staff> getStaffList(RequestStaff requestStaff) {
        // 参数合法性校验
        if (requestStaff.getPageNumber() == null) {
            // 默认第一页
            requestStaff.setPageNumber(1);
        }

        if (requestStaff.getPagerSize() == null) {
            // 默认查询十条记录
            requestStaff.setPagerSize(10);
        }
        // 初始化起点
        requestStaff.setOffset((requestStaff.getPageNumber() - 1) * requestStaff.getPagerSize());

        if (!"ASC".equalsIgnoreCase(requestStaff.getOrderDirection())) {
            // 默认升序
            requestStaff.setOrderDirection("DESC");
        }

        if (requestStaff.getOrderField() == null) {
            requestStaff.setOrderField("id");
        }
        return staffMapper.selectStaffList(requestStaff);
    }
}

